package cn.wolfcode.crm.web.controller;/**
 * Created by 10797 on 2018/7/12.
 */

import cn.wolfcode.crm.domain.Client;
import cn.wolfcode.crm.domain.GuaranteeBill;
import cn.wolfcode.crm.domain.GuaranteeBillVO;
import cn.wolfcode.crm.query.GuaranteeBillQueryObject;
import cn.wolfcode.crm.service.IGuaranteeBillService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: crm
 * @description: 暂存单组件
 * @author: Mr.chen
 * @create: 2018-07-12 12:08
 **/

@Controller
@RequestMapping("guaranteeBill")
public class GuaranteeBillController {

    @Autowired
    private IGuaranteeBillService guaranteeBillService;

    @RequestMapping("")
    public String list(){
        return "/guaranteeBill/list";
    }

    @RequestMapping("queryTemporary")
    @ResponseBody
    public PageResult main(GuaranteeBillQueryObject qo) {

        return guaranteeBillService.query(qo);
    }
    @RequestMapping("selectClientByBillId")
    @ResponseBody
    public Client selectClientByBillId(Long id){

        return guaranteeBillService.selectClientByBillId(id);
    }
    @RequestMapping("editGuaranteeBill")
    @ResponseBody
    public JsonResult editGuaranteeBill(GuaranteeBillVO vo){
        try{
            guaranteeBillService.editGuaranteeBill(vo);
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("保存失败");
        }
        return new JsonResult();
    }

    //跳转到未审核状态的页面单据
    @RequestMapping("viewUnAudit")
    public String viewUnAudit(){
        return "/guaranteeBill/unAuditedBill";
    }

    //查询未审核状态的表,时刻记住只要不是主页面跳转就要立马加上@ResponseBody,被坑了好多次了
    @RequestMapping("queryUnAudit")
    @ResponseBody
    public PageResult queryUnAudit(GuaranteeBillQueryObject qo){

        return guaranteeBillService.query(qo);
    }
    /*
    * 拒保方法:
    *   改变当前保单的状态为拒保状态
    * */
    @RequestMapping("changeBillState")
    @ResponseBody
    public JsonResult changeBillState(String number){
        try{
            guaranteeBillService.changeBillState(number);
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("拒保失败");
        }
        return new JsonResult();
    }
    /*
    * 退回修改状态,在退回单当中进行查看
    * */
    @RequestMapping("backToChangeBill")
    @ResponseBody
    public JsonResult backToChangeBill(String number,String info){
        try{
            guaranteeBillService.backToChangeBill(number,info);
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("拒保失败");
        }
        return new JsonResult();
    }

    /*
    * 审核通过的方法
    * */
    @RequestMapping("auditBill")
    @ResponseBody
    public JsonResult auditBill(Long id){
        try{
            guaranteeBillService.auditBill(id);
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("审核失败");
        }
        return new JsonResult();
    }

}
